

# Listener

<div class="api-docs__separator" data-reactroot="">

---

</div><div class="api-docs__import" data-reactroot="">

```ts
import { Listener } from "@hyper-fetch/sockets"
```

</div><div class="api-docs__section">

## Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [listener/listener.ts:8](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/listener/listener.ts#L8)

</p><div class="api-docs__section">

## Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="socket"><td class="api-docs__param-name required">

### socket 

`Required`

</td><td class="api-docs__param-type">

`Socket<AdapterType>`

</td></tr><tr param-data="listenerOptions"><td class="api-docs__param-name optional">

### listenerOptions 

`Optional`

</td><td class="api-docs__param-type">

`ListenerOptionsType<Endpoint, AdapterType>`

</td></tr></tbody></table></div><div class="api-docs__section">

## Properties

</div><div class="api-docs__properties"><div class="api-docs__property" property-data="connections"><h3 class="api-docs__name">

### `connections`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [listener/listener.ts:17](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/listener/listener.ts#L17)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
Set<ConnectMethodType<AdapterType, Response>>
```

</div><hr/></div><div class="api-docs__property" property-data="endpoint"><h3 class="api-docs__name">

### `endpoint`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [listener/listener.ts:14](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/listener/listener.ts#L14)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
Endpoint
```

</div><hr/></div><div class="api-docs__property" property-data="listenerOptions"><h3 class="api-docs__name">

### `listenerOptions`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [listener/listener.ts:21](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/listener/listener.ts#L21)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
ListenerOptionsType<Endpoint, AdapterType>
```

</div><hr/></div><div class="api-docs__property" property-data="options"><h3 class="api-docs__name">

### `options`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [listener/listener.ts:16](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/listener/listener.ts#L16)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
ExtractListenerOptionsType<AdapterType>
```

</div><hr/></div><div class="api-docs__property" property-data="params"><h3 class="api-docs__name">

### `params`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [listener/listener.ts:15](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/listener/listener.ts#L15)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
ParamsType
```

</div><hr/></div><div class="api-docs__property" property-data="socket"><h3 class="api-docs__name">

### `socket`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [listener/listener.ts:20](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/listener/listener.ts#L20)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
Socket<AdapterType>
```

</div><hr/></div></div><div class="api-docs__section">

## Methods

</div><div class="api-docs__methods"><div class="api-docs__method" method-data="listen"><h3 class="api-docs__name">

### `listen()`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [listener/listener.ts:67](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/listener/listener.ts#L67)

</p><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
(options: ExtractRouteParams<ExtractListenerEndpointType<Listener>> extends NegativeTypes ? {
  callback: ListenerCallbackType<Adapter, ExtractListenerResponseType<Listener>>;
} : (ExtractListenerHasParams<Listener> extends false ? {
  callback: ListenerCallbackType<Adapter, ExtractListenerResponseType<Listener>>;
  params: ExtractRouteParams<ExtractListenerEndpointType<Listener>>;
} : {
  callback: ListenerCallbackType<Adapter, ExtractListenerResponseType<Listener>>;
  params: never;
})) => () => void
```

</div><hr/></div><div class="api-docs__method" method-data="clone"><h3 class="api-docs__name">

### `clone()`

</h3><div class="api-docs__section">

#### Preview

</div><div class="api-docs__preview fn">

```ts
clone<Params>(options)
```

</div><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [listener/listener.ts:56](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/listener/listener.ts#L56)

</p><div class="api-docs__section">

#### Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="options"><td class="api-docs__param-name optional">

#### options 

`Optional`

</td><td class="api-docs__param-type">

`Partial<ListenerOptionsType<Endpoint, AdapterType>>`

</td></tr></tbody></table></div><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
Listener<Response, Endpoint, AdapterType, Params>
```

</div><hr/></div><div class="api-docs__method" method-data="onData"><h3 class="api-docs__name">

### `onData()`

</h3><div class="api-docs__section">

#### Preview

</div><div class="api-docs__preview fn">

```ts
onData(callback)
```

</div><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">

Attach global logic to the received events

</span></div><p class="api-docs__definition">

Defined in [listener/listener.ts:51](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/listener/listener.ts#L51)

</p><div class="api-docs__section">

#### Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="callback"><td class="api-docs__param-name required">

#### callback 

`Required`

</td><td class="api-docs__param-type">

`ConnectMethodType<AdapterType, Response>`

</td></tr></tbody></table></div><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
Listener<Response, Endpoint, AdapterType, HasParams>
```

</div><hr/></div><div class="api-docs__method" method-data="setOptions"><h3 class="api-docs__name">

### `setOptions()`

</h3><div class="api-docs__section">

#### Preview

</div><div class="api-docs__preview fn">

```ts
setOptions(options)
```

</div><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [listener/listener.ts:28](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/listener/listener.ts#L28)

</p><div class="api-docs__section">

#### Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="options"><td class="api-docs__param-name required">

#### options 

`Required`

</td><td class="api-docs__param-type">

`ExtractListenerOptionsType<AdapterType>`

</td></tr></tbody></table></div><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
Listener<Response, Endpoint, AdapterType, HasParams>
```

</div><hr/></div><div class="api-docs__method" method-data="setParams"><h3 class="api-docs__name">

### `setParams()`

</h3><div class="api-docs__section">

#### Preview

</div><div class="api-docs__preview fn">

```ts
setParams(params)
```

</div><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [listener/listener.ts:32](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/listener/listener.ts#L32)

</p><div class="api-docs__section">

#### Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="params"><td class="api-docs__param-name required">

#### params 

`Required`

</td><td class="api-docs__param-type">

`ExtractRouteParams<Endpoint>`

</td></tr></tbody></table></div><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
Listener<Response, Endpoint, AdapterType, true>
```

</div><hr/></div></div>